package faw.car.sdv.condition;
import faw.car.sdv.annotation.SdvAnnotations.*;

/*
 * -----  注解说明 -----
 * @SdvFuncGroup：注解在类上，用于标识该类为一个功能组
 * @SdvFunc：注解在方法上，用于标识该方法为一个功能
 * @SdvClass：注解在类上，用于标识该类为一个类
 * @SdvOpFunc：注解在方法上，用于标识该方法为一个操作函数
 * @SdvOpParameter：注解在方法参数上，用于标识该参数为一个操作函数的参数
 * @SdvOpReturn：注解在方法返回值上，用于标识该返回值为一个操作函数的返回值
 */

@SdvOperator(name = "ConditionControl", desc = "空调控制")
@SdvOperatorMeta(type = "business", version = "1.0.0", date = "2023-04-01", author = "faw")
@SdvOperatorDependency(packageName = "", packageVersion = "", operator = "", operatorVersion = "")
public class ConditionControl {

    private boolean isOn;
    private int temperature;

    public ConditionControl() {
        this.isOn = false;
        this.temperature = 25;
    }

    /**
     * 打开空调
     */
    @SdvOpFunc(name = "turnOn", desc = "打开空调", type = "execute")
    public void turnOn() {
        this.isOn = true;
        System.out.println("空调已打开");
    }

    /**
     * 关闭空调
     */
    @SdvOpFunc(name = "turnOff", desc = "关闭空调", type = "execute")
    public void turnOff() {
        this.isOn = false;
        System.out.println("空调已关闭");
    }

    /**
     * 设置空调温度
     * @param temperature 温度值
     */
    @SdvOpFunc(name = "setTemperature", desc = "设置空调温度", type = "execute")
    public void setTemperature(
        @SdvOpParameter(name = "temperature", desc = "温度值", type = "int", validRange = "[16,30]")
        int temperature
    ) {
        if (temperature >= 16 && temperature <= 30) {
            this.temperature = temperature;
            System.out.println("空调温度已设置为: " + temperature + "°C");
        } else {
            System.out.println("温度设置无效，范围应为 16°C 到 30°C");
        }
    }

    /**
     * 获取当前空调温度
     * @return 当前温度
     */
    @SdvOpFunc(name = "getTemperature", desc = "获取当前空调温度", type = "read")
    @SdvOpReturn(name = "temperature", desc = "当前温度", type = "int")
    public int getTemperature() {
        return this.temperature;
    }

    /**
     * 检查空调是否开启
     * @return 如果空调开启返回 true，否则返回 false
     */
    @SdvOpFunc(name = "isOn", desc = "检查空调是否开启", type = "check")
    public boolean isOn() {
        return this.isOn;
    }
}